package com.hw.protocol.tool.decode.hw;

import io.netty.buffer.ByteBuf;

/**
 * @author : lihy
 * @date : 2023/3/23 9:52
 * description:
 */
public interface IHisDecode {

    default String getTime(ByteBuf dataBuf){
        int year = getInt(dataBuf);
        int month = getInt(dataBuf);
        int date = getInt(dataBuf);
        int week = getInt(dataBuf);
        int hour = getInt(dataBuf);
        int minute = getInt(dataBuf);
        int second = getInt(dataBuf);
        return String.format("20%02d-%02d-%02d %02d:%02d:%02d", year, month, date, hour, minute, second);
    }

    default int getInt(ByteBuf dataBuf){
        return Integer.parseInt(Integer.toHexString(dataBuf.readByte() & 0xff));
    }
}
